#include "Gk.h"

namespace gk
{
	void StateBlock::SetDefault()
	{
		m_renderStateValues[RenderState::DepthTest].m_renderStateValue = RenderStateValue::DepthTestEnabled;
		m_renderStateValues[RenderState::DepthWrite].m_renderStateValue = RenderStateValue::DepthWriteEnabled;
		m_renderStateValues[RenderState::AlphaTest].m_renderStateValue = RenderStateValue::AlphaTestDisabled;
		m_renderStateValues[RenderState::AlphaTestThreshold].m_intValue = 0;
		m_renderStateValues[RenderState::CullFace].m_renderStateValue = RenderStateValue::CullFaceBack;

		for (cr::uint32_t i = SamplerIndex::First; i < SamplerIndex::NumberOf; ++i)
		{
			m_samplerStateValues[i][SamplerState::AddressModeU].m_samplerStateValue = SamplerStateValue::AddressModeWrap;
			m_samplerStateValues[i][SamplerState::AddressModeV].m_samplerStateValue = SamplerStateValue::AddressModeWrap;
			m_samplerStateValues[i][SamplerState::AddressModeW].m_samplerStateValue = SamplerStateValue::AddressModeWrap;
			m_samplerStateValues[i][SamplerState::FilterMin].m_samplerStateValue = SamplerStateValue::FilterAnisotropic;
			m_samplerStateValues[i][SamplerState::FilterMag].m_samplerStateValue = SamplerStateValue::FilterAnisotropic;
			m_samplerStateValues[i][SamplerState::FilterMip].m_samplerStateValue = SamplerStateValue::FilterLinear;
			m_samplerStateValues[i][SamplerState::FilterMaxAnisos].m_intValue = 16;
			m_samplerStateValues[i][SamplerState::FilterMipBias].m_floatValue = 0.0f;
		}
	}

	void StateBlock::Invalidate()
	{
		for (cr::uint32_t j = RenderState::First; j < RenderState::NumberOf; ++j)
		{
			m_renderStateValues[j].m_renderStateValue= RenderStateValue::Invalid;
		}

		for (cr::uint32_t i = SamplerIndex::First; i < SamplerIndex::NumberOf; ++i)
		{
			for (cr::uint32_t j = SamplerState::First; j < SamplerState::NumberOf; ++j)
			{
				m_samplerStateValues[i][j].m_samplerStateValue = SamplerStateValue::Invalid;
			}
		}
	}
}